<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="旅游区类型" prop="tourismType">
        <el-select v-model="queryParams.tourismType" placeholder="请选择旅游区类型" clearable size="small">
          <el-option label="旅游区" value="旅游区" />
          <el-option label="旅游游览区(旅游地)" value="旅游游览区(旅游地)" />
          <el-option label="旅游景区" value="旅游景区" />
          <el-option label="旅游点" value="旅游点" />
          <el-option label="旅游景点" value="旅游景点" />
          <el-option label="旅游景物" value="旅游景物" />
        </el-select>
      </el-form-item>
      <el-form-item label="景点名称" prop="attractionName">
        <el-input
          v-model="queryParams.attractionName"
          placeholder="请输入景点名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="场所等级分布" prop="placeRatingDistribution">
        <el-select v-model="queryParams.placeRatingDistribution" placeholder="请选择场所等级分布" clearable size="small">
          <el-option label="一级场所" value="一级场所" />
          <el-option label="二级场所" value="二级场所" />
          <el-option label="三级场所" value="三级场所" />
          <el-option label="四级场所" value="四级场所" />
        </el-select>
      </el-form-item>
      <el-form-item label="管控类型" prop="controlType">
        <el-select v-model="queryParams.controlType" placeholder="请选择管控类型" clearable size="small">
          <el-option label="累计纳入" value="累计纳入" />
          <el-option label="管控中" value="管控中" />
          <el-option label="已闭环" value="已闭环" />
        </el-select>
      </el-form-item>
      <el-form-item label="智管类型" prop="smartManagementType">
        <el-select v-model="queryParams.smartManagementType" placeholder="请选择智管类型" clearable size="small">
          <el-option label="一级智管" value="一级智管" />
          <el-option label="二级智管" value="二级智管" />
          <el-option label="三级智管" value="三级智管" />
        </el-select>
      </el-form-item>
      <el-form-item label="智管时间" prop="smartManagementTime">
        <el-input
          v-model="queryParams.smartManagementTime"
          placeholder="请输入智管时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['information:appOtherFkzg:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['information:appOtherFkzg:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['information:appOtherFkzg:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['information:appOtherFkzg:export']"
        >导出</el-button>
      </el-col>
      <div class="top-right-btn">
        <el-tooltip class="item" effect="dark" content="刷新" placement="top">
          <el-button size="mini" circle icon="el-icon-refresh" @click="handleQuery" />
        </el-tooltip>
        <el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top">
          <el-button size="mini" circle icon="el-icon-search" @click="showSearch=!showSearch" />
        </el-tooltip>
      </div>
    </el-row>

    <el-table v-loading="loading" :data="appOtherFkzgList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="旅游区类型" align="center" prop="tourismType" />
      <el-table-column label="景点名称" align="center" prop="attractionName" />
      <el-table-column label="场所等级分布" align="center" prop="placeRatingDistribution" />
      <el-table-column label="管控类型" align="center" prop="controlType" />
      <el-table-column label="智管类型" align="center" prop="smartManagementType" />
      <el-table-column label="智管时间" align="center" prop="smartManagementTime" />
      <el-table-column label="二维码" align="center" prop="zxingUrl">
        <template slot-scope="scope">
          <div class="demo-image__preview">
            <el-image style="height: 30%;width: 30%" :src="scope.row.zxingUrl" :zIndex="9999"
                      :preview-src-list="[scope.row.zxingUrl]" @click.stop="handleClickItem"></el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['information:appOtherFkzg:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['information:appOtherFkzg:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改分级智管对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="旅游区类型">
          <el-select v-model="form.tourismType" placeholder="请选择旅游区类型">
            <el-option label="旅游区" value="旅游区" />
            <el-option label="旅游游览区(旅游地)" value="旅游游览区(旅游地)" />
            <el-option label="旅游景区" value="旅游景区" />
            <el-option label="旅游点" value="旅游点" />
            <el-option label="旅游景点" value="旅游景点" />
            <el-option label="旅游景物" value="旅游景物" />
          </el-select>
        </el-form-item>
        <el-form-item label="景点名称" prop="attractionName">
          <el-input v-model="form.attractionName" placeholder="请输入景点名称" />
        </el-form-item>
        <el-form-item label="场所等级分布">
          <el-select v-model="form.placeRatingDistribution" placeholder="请选择场所等级分布">
            <el-option label="一级场所" value="一级场所" />
            <el-option label="二级场所" value="二级场所" />
            <el-option label="三级场所" value="三级场所" />
            <el-option label="四级场所" value="四级场所" />
          </el-select>
        </el-form-item>
        <el-form-item label="管控类型">
          <el-select v-model="form.controlType" placeholder="请选择管控类型">
            <el-option label="累计纳入" value="累计纳入" />
            <el-option label="管控中" value="管控中" />
            <el-option label="已闭环" value="已闭环" />
          </el-select>
        </el-form-item>
        <el-form-item label="智管类型">
          <el-select v-model="form.smartManagementType" placeholder="请选择智管类型">
            <el-option label="一级智管" value="一级智管" />
            <el-option label="二级智管" value="二级智管" />
            <el-option label="三级智管" value="三级智管" />
          </el-select>
        </el-form-item>
        <el-form-item label="智管时间" prop="smartManagementTime">
          <el-input v-model="form.smartManagementTime" placeholder="请输入智管时间" />
        </el-form-item>
        <el-form-item label="二维码颜色">
          <el-select v-model="form.zxingCore" placeholder="二维码颜色">
            <el-option label="红" value="红" />
            <el-option label="黑" value="黑" />
            <el-option label="黄" value="黄" />
            <el-option label="绿" value="绿" />
            <el-option label="蓝" value="蓝" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAppOtherFkzg, getAppOtherFkzg, delAppOtherFkzg, addAppOtherFkzg, updateAppOtherFkzg } from "@/api/information/appOtherFkzg";

export default {
  name: "AppOtherFkzg",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 分级智管表格数据
      appOtherFkzgList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tourismType: null,
        attractionName: null,
        placeRatingDistribution: null,
        controlType: null,
        smartManagementType: null,
        smartManagementTime: null,
        zxingCore: null,
        zxingUrl: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询分级智管列表 */
    getList() {
      this.loading = true;
      listAppOtherFkzg(this.queryParams).then(response => {
        this.appOtherFkzgList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tourismType: null,
        attractionName: null,
        placeRatingDistribution: null,
        controlType: null,
        smartManagementType: null,
        smartManagementTime: null,
        zxingCore: null,
        zxingUrl: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加分级智管";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAppOtherFkzg(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改分级智管";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAppOtherFkzg(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addAppOtherFkzg(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除分级智管编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delAppOtherFkzg(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('information/appOtherFkzg/export', {
        ...this.queryParams
      }, `information_appOtherFkzg.xlsx`)
    },
    handleClickItem(row){
      this.$nextTick(() => {
        // 获取遮罩层dom
        let domImageMask = document.querySelector('.el-image-viewer__mask')
        if (!domImageMask) {
          return
        }
        domImageMask.addEventListener('click', () => {
          // 点击遮罩层时调用关闭按钮的 click 事件
          document.querySelector('.el-image-viewer__close').click()
        })
      })
    },
  }
};
</script>
